from typing import Any, Awaitable, Callable, Dict

from aiogram import BaseMiddleware
from aiogram.types import TelegramObject

from app.bot.services.paypalych_api.client import PayPalychClient


class PaymentMiddleware(BaseMiddleware):
    def __init__(self, payment_client: PayPalychClient) -> None:
        self.payment_client = payment_client

    async def __call__(
        self,
        handler: Callable[[TelegramObject, Dict[str, Any]], Awaitable[Any]],
        event: TelegramObject,
        data: Dict[str, Any],
    ) -> Any:

        data["payment_client"] = self.payment_client
        result = await handler(event, data)
        return result
